<?php
if ( ! defined( 'NV_IS_VIDEO_ADMIN' ) ) { die( 'Stop!!!' ); } 
$page_title = "Thêm video"; 
$contents="";
$add = 0; 
$error = ""; 
if ( $nv_Request->get_int( 'add', 'post' ) == 1 ) 
{ 
	///////////////////////////////////////////////////
	$list = $_FILES["file"]["name"];
  $contents.= "File đã chọn: " . $_FILES["file"]["name"] . "<br />";
  $contents.= "Loại: " . $_FILES["file"]["type"] . "<br />";
  $contents.= "Kích thước: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  $contents.= "Ở thư mục: " . $_FILES["file"]["tmp_name"];
  if (file_exists("../".NV_UPLOADS_DIR . "/" . $module_name."/list/" . $_FILES["file"]["name"]))
    {
      $contents.= $_FILES["file"]["name"] . " Đã tồn tại. ";
    }
  else
    {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "../".NV_UPLOADS_DIR . "/" . $module_name."/list/" . $_FILES["file"]["name"]);
      $contents.= "<br />Di chuyển tới: " . "../upload/" . $_FILES["file"]["name"];
    }
	$title = filter_text_input( 'title', 'post', '', 1 ); 
	$duongdan = filter_text_input( 'duongdan', 'post', '', 1 ); 
	$thumb = filter_text_input( 'thumb', 'post', '', 1 );
	$theloai = $nv_Request->get_int( 'theloai', 'post',0 );
	$who_post = filter_text_input( 'who_post', 'post', '', 1 );
	if ( empty( $title ) ) { $error = "Lỗi: Chưa điền tên album"; } else
	if ( empty( $thumb ) ) { $error = "Lỗi: Chưa điền thông tin ảnh hiển thị"; } else
	if ( empty( $who_post ) ) { $error = "Lỗi: Chưa có người đăng"; }
	else 
	{ 
		$query = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "` (`id`, `title`, `thumb`, `theloai`, `duongdan`, `who_post`, `list`, `num_view`) VALUES ( NULL, " . $db->dbescape( $title ) . ", " . $db->dbescape( $thumb ) . ", " . $db->dbescape( $theloai ) . ", " . $db->dbescape( $duongdan ) . ", " . $db->dbescape( $who_post ) . ", " . $db->dbescape( $list ).",0)"; 
		if ( $db->sql_query_insert_id( $query ) ) 
		{ 
			$db->sql_freeresult();
			$contents .= "<br /><strong>Video đã thêm thành công</strong><br />";
		} 
		else { $error = "Có lỗi trong quá trình lưu dữ liệu hãy kiểm tra lại"; } 
	} 
} 
if ( $error != "" ) 
{ 
	$contents .= "<div class=\"quote\" style=\"width:780px;\">\n"; 
	$contents .= "<blockquote class=\"error\"><span>" . $error . "</span></blockquote>\n"; 
	$contents .= "</div>\n"; 
	$contents .= "<div class=\"clear\"></div>\n"; 
} 
$contents .= "<form action=\"" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=add\" enctype=\"multipart/form-data\" method=\"post\">"; 
$contents .= "<br /><p><strong>Nhập vào đầy đủ thông tin cho Video:</strong> Lưu ý các thông tin đều là bắt buộc</p>";  
$contents .= "	<table class=\"tab1\">\n";  
$contents .= " 	<tr>\n"; 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$contents .= " 		<td width=\"30%\"><strong>Tên video:</strong></td>\n"; 
$contents .= " 		<td>\n"; 
$contents .= " 			<input type=\"text\" name=\"title\" size=\"100\">\n"; 
$contents .= " 		</td>\n"; 
$contents .= " 	</tr>\n"; 
$contents .= " 	<tr>\n"; 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$contents .= " 		<td width=\"30%\"><strong>Chọn thể loại:</strong>\n"; 
$contents .= " 		<td>\n"; 
$contents .= " 			<select name=\"theloai\" >";
$sql = "SELECT id, num,  title FROM `" . NV_PREFIXLANG . "_" . $module_data . "_category` ORDER BY num DESC";
$resuilt = $db->sql_query( $sql );
while ( $row = $db->sql_fetchrow( $resuilt ) )
{
$contents .= "				<option value=\"".$row['num']."\">".$row['title']."</option>";
}
$contents .= "			</select>\n"; 
$contents .= " 		</td>\n"; 
$contents .= " 	</tr>\n"; 
$contents .= " 	<tr>\n"; 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$contents .= " 		<td width=\"30%\"><strong>Người đăng:</strong></td>\n"; 
$contents .= " 		<td colspan=\"2\">\n"; 
$contents .= " 			<input type=\"text\" name=\"who_post\" size=\"100\">\n"; 
$contents .= " 		</td>\n"; 
$contents .= " 	</tr>\n"; 
$contents .= " 	<tr>\n"; 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$contents .= " 		<td width=\"30%\"><strong>Đường dẫn:</strong>Nếu video có playlist thì để trống</td>\n"; 
$contents .= " 		<td colspan=\"2\">\n"; 
$contents .= " 			<input type=\"text\" name=\"duongdan\" size=\"100\">\n"; 
$contents .= " 		</td>\n"; 
$contents .= " 	</tr>\n"; 
$contents .= " 	<tr>\n"; 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$contents .= " 		<td width=\"30%\"><strong>Ảnh hiển thị:</strong></td>\n"; 
$contents .= " 		<td style=\"background:#eee;\" valign=\"middle\">
                            	<input style=\"width: 400px;\" name=\"thumb\" id=\"thumb\" type=\"text\" />
                            </td>
                            <td style=\"background:#eee;\" valign=\"middle\">
                            <input value=\"Chọn ảnh\" name=\"selectimg\" type=\"button\"/>
                            <script type=\"text/javascript\">
							$(\"input[name=selectimg]\").click(function()
							{
								var area = \"thumb\"; // return value area
								var type = \"image\";
								var path = \"".NV_UPLOADS_DIR . "/" . $module_name."/thumb\";
								nv_open_browse_file(\"".NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=upload&popup=1&area=" + area+"&path="+path+"&type="+type, "NVImg", "850", "500","resizable=no,scrollbars=no,toolbar=no,location=no,status=no'."\");
								return false;
							});
						</script></td> ";
$contents .= " 	</tr>\n"; 
$contents .= " 	<tr>\n"; 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$contents .= " 		<td width=\"30%\"><strong>Playlist:</strong>Nếu video có playlist thì chọn playlist</td>\n"; 
$contents .= " 		<td style=\"background:#eee;\" valign=\"middle\">
                        <input type=\"file\" name=\"file\" id=\"file\" />
                    </td>";
$contents .= " 	</tr>\n"; 
$contents .= "</table>\n"; 
$contents .= "<table class=\"tab2\" align=\"center\">\n"; 
$contents .= " 	<tr>\n"; 
$contents .= " 		<td style=\"text-align:center;\">\n"; 
$contents .= " 		<input type=\"submit\" value=\"Lưu\"/>\n"; 
$contents .= " 		<input name=\"add\" type=\"hidden\" value=\"1\" />\n"; 
$contents .= " 		<input type=\"hidden\" name =\"" . NV_NAME_VARIABLE . "\"value=\"" . $module_name . "\" />"; $contents .= " 		<input type=\"hidden\" name =\"" . NV_OP_VARIABLE . "\"value=\"" . $op . "\" />"; 
$contents .= " 		</td>\n"; 
$contents .= " 	</tr>\n"; 
$contents .= "	</table>\n"; 
$contents .= "</form>\n"; 
include ( NV_ROOTDIR . "/includes/header.php" ); 
echo nv_admin_theme( $contents ); 
include ( NV_ROOTDIR . "/includes/footer.php" ); 
?>